package com.juyu.miliao.api.dao.redis;

import com.juyu.miliao.api.util.RedisKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

/**
 * @author pengs
 */
@Repository
public class BuyPrivateRedisDao {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public void insertBuyPrivate(int buyUserId, int privateId) {
        stringRedisTemplate.opsForSet().add(RedisKeys.SET_USERPRIVATEPHOTOID.getValue(privateId), String.valueOf(buyUserId));
    }

    public Boolean isExist(long tokenId, int privateId) {
        return stringRedisTemplate.opsForSet().isMember(RedisKeys.SET_USERPRIVATEPHOTOID.getValue(privateId), String.valueOf(tokenId));
    }

    public void deletePrivateByPrivateId(int privateId) {
        stringRedisTemplate.delete(RedisKeys.SET_USERPRIVATEPHOTOID.getValue(privateId));
    }

    public long getPicBuyNum(int privateId){
        return stringRedisTemplate.opsForSet().size(RedisKeys.SET_USERPRIVATEPHOTOID.getValue(privateId));
    }
    public Boolean hasKeyBuyChatPhoto(String key){
        return stringRedisTemplate.hasKey(key);
    }

    public void setBuyChatPhoto(String key) {
        stringRedisTemplate.opsForValue().set(key,1+"",1, TimeUnit.SECONDS);
    }
}
